using System;
using System.Configuration;
using System.Data;
using digit.Core;



namespace SMS.ServiceManager
{
    public class CountryManager
    {
        #region CONSTRUCTORS
        static CountryManager()
        {
            _data = new CountryData(Util.GetConnectionString("SMSSERVICE"));
            _error = "";
        }
        #endregion

        #region ATTRIBUTES
        private static CountryData _data;
        private static string _error;
        #endregion

        #region PROPERTIES
        public static string ErrorMessage
        {
            get
            {
                return _error;
            }
        }

        #endregion

        #region METHODS
        public static bool Insert(string countryName, byte orderNo, string createdBy, DateTime createdDate, byte status)
        {
            _error = "";
            try
            {
                object[] values = new object[5];
                values[0] = Util.ReplaceNullTo(countryName, DBNull.Value);
                values[1] = Util.ReplaceNullTo(orderNo, DBNull.Value);
                values[2] = Util.ReplaceNullTo(createdBy, DBNull.Value);
                values[3] = Util.ReplaceNullTo(createdDate, DBNull.Value);
                values[4] = Util.ReplaceNullTo(status, DBNull.Value);

                return _data.Insert(values);
            }
            catch (Exception ex)
            {
                _error = ex.Message;
                return false;
            }
        }

        public static bool Insert(CountryInfo info)
        {
            _error = "";
            try
            {
                object[] values = new object[5];
                values[0] = Util.ReplaceNullTo(info.CountryName, DBNull.Value);
                values[1] = Util.ReplaceNullTo(info.OrderNo, DBNull.Value);
                values[2] = Util.ReplaceNullTo(info.CreatedBy, DBNull.Value);
                values[3] = Util.ReplaceNullTo(info.CreatedDate, DBNull.Value);
                values[4] = Util.ReplaceNullTo(info.Status, DBNull.Value);

                return _data.Insert(values);
            }
            catch (Exception ex)
            {
                _error = ex.Message;
                return false;
            }
        }

        public static bool Update(int countryID, string countryName, byte orderNo, string createdBy, DateTime createdDate, byte status)
        {
            _error = "";
            try
            {
                object[] values = new object[6];
                values[0] = countryID;
                values[1] = Util.ReplaceNullTo(countryName, DBNull.Value);
                values[2] = Util.ReplaceNullTo(orderNo, DBNull.Value);
                values[3] = Util.ReplaceNullTo(createdBy, DBNull.Value);
                values[4] = Util.ReplaceNullTo(createdDate, DBNull.Value);
                values[5] = Util.ReplaceNullTo(status, DBNull.Value);

                return _data.Update(values);
            }
            catch (Exception ex)
            {
                _error = ex.Message;
                return false;
            }
        }

        public static bool Update(CountryInfo info)
        {
            _error = "";
            try
            {
                object[] values = new object[6];
                values[0] = info.CountryID;
                values[1] = Util.ReplaceNullTo(info.CountryName, DBNull.Value);
                values[2] = Util.ReplaceNullTo(info.OrderNo, DBNull.Value);
                values[3] = Util.ReplaceNullTo(info.CreatedBy, DBNull.Value);
                values[4] = Util.ReplaceNullTo(info.CreatedDate, DBNull.Value);
                values[5] = Util.ReplaceNullTo(info.Status, DBNull.Value);

                return _data.Update(values);
            }
            catch (Exception ex)
            {
                _error = ex.Message;
                return false;
            }
        }

        public static bool Delete(int countryID)
        {
            _error = "";
            try
            {
                object[] values = { countryID };
                return _data.Delete(values);
            }
            catch (Exception ex)
            {
                _error = ex.Message;
                return false;
            }
        }

        public static bool Delete(CountryInfo info)
        {
            _error = "";
            try
            {
                object[] values = { info.CountryID };
                return _data.Delete(values);
            }
            catch (Exception ex)
            {
                _error = ex.Message;
                return false;
            }
        }

        public static CountryInfo Select(int countryID)
        {
            _error = "";
            try
            {
                object[] values = { countryID };
                DataTable dTable = _data.Select(values);
                if (dTable.Rows.Count < 1) return null;


                CountryInfo info = new CountryInfo(dTable.Rows[0]);
                return info;
            }
            catch (Exception ex)
            {
                _error = ex.Message;
                return null;
            }
        }

        public static DataTable SelectAll()
        {
            _error = "";
            try
            {
                return _data.SelectAll();
            }
            catch (Exception ex)
            {
                _error = ex.Message;
                return null;
            }
        }

        public static DataTable SelectCountryConfig()
        {
            _error = "";
            try
            {
                object[] values = new object[0];
                return _data.SelectCountryConfig(values);
            }
            catch (Exception ex)
            {
                _error = ex.Message;
                return null;
            }
        }

        #endregion

    }
}